package org.vy.dal.dao;

import java.util.List;

import org.vy.dal.QueryManager;

public class VySantSamajDAO {
	private static final String FIND_BY_PK = "SELECT * FROM <TABLE> WHERE SANT_SAMAJ_ID = m_SantSamajId";
	private static final String FIND_BY_PARAMETER = "SELECT * FROM <TABLE> WHERE 1 = 1 ";
	private static final String UPDATE = "UPDATE <TABLE> SET SANT_SAMAJ_NAME = m_SantSamajName,EMAIL=m_Email,CONTACT_NO=m_ContactNum,FAX=m_Fax,ADDRESS_ID=m_Address,CONTACT_VY_ID1=m_ContactVyid1,CONTACT_VY_ID2=m_ContactVyid2,COMMENT=m_Comment,LAST_UPDATED_BY=m_LastUpdatedBy, LAST_UPDATED_ON=m_LastUpdatedOn WHERE SANT_SAMAJ_ID = m_SantSamajId";
	private static final String INSERT = "INSERT INTO <TABLE> (SANT_SAMAJ_ID, SANT_SAMAJ_NAME, EMAIL, CONTACT_NO, FAX, ADDRESS_ID, CONTACT_VY_ID1, CONTACT_VY_ID2, COMMENT, LAST_UPDATED_BY, LAST_UPDATED_ON) VALUES(m_SantSamajId,m_SantSamajName,m_Email,m_ContactNum,m_Fax,m_Address,m_ContactVyid1,m_ContactVyid2,m_Comment,m_LastUpdatedBy,m_LastUpdatedOn)";
	private static final String DELETE = "DELETE FROM <TABLE> WHERE SANT_SAMAJ_ID = m_SantSamajId";

	public static VySantSamajDO findByPK(String key) throws Exception {
		VySantSamajDO dto = new VySantSamajDO();
		dto.setSantSamajId(key);
		dto = (VySantSamajDO) QueryManager.executeQuery(dto, FIND_BY_PK);
		return dto;
	}

	public static VySantSamajDO insert(VySantSamajDO dto) throws Exception {

		dto = (VySantSamajDO) QueryManager.executeInsert(dto, INSERT);
		return dto;
	}

	public static VySantSamajDO update(VySantSamajDO dto) throws Exception {
		int i = QueryManager.executeUpdate(dto, UPDATE);
		if (i > 0)
			return dto;
		else
			return null;
	}

	public static VySantSamajDO delete(String key) throws Exception {
		VySantSamajDO dto = new VySantSamajDO();
		dto.setSantSamajId(key);
		boolean i = QueryManager.executeDelete(dto, DELETE);
		if (i == true)
			return dto;
		else
			return null;
	}

	@SuppressWarnings("unchecked")
	public static List<VySantSamajDO> findByParam(VySantSamajDO dto)
			throws Exception {

		StringBuilder sb = new StringBuilder(FIND_BY_PARAMETER);
		if (dto.getSantSamajId() != null) {
			sb.append(" AND SANT_SAMAJ_ID LIKE '%" + dto.getSantSamajId()
					+ "%' ");
		}
		if (dto.getSantSamajName() != null) {
			sb.append(" AND SANT_SAMAJ_NAME LIKE '%" + dto.getSantSamajName()
					+ "%' ");
		}
		if (dto.getEmail() != null) {
			sb.append(" AND EMAIL LIKE '%" + dto.getEmail() + "%' ");

		}
		if (dto.getContactNum() != null) {
			sb.append(" AND CONTACT_NO LIKE '%" + dto.getContactNum() + "%' ");
		}
		if (dto.getFax() != null) {
			sb.append(" AND FAX LIKE '%" + dto.getFax() + "%' ");
		}
		if (dto.getAddress() != null) {
			sb.append(" AND ADDRESS_ID LIKE '%" + dto.getAddress() + "%' ");

		}
		if (dto.getContactVyid1() != null) {
			sb.append(" AND CONTACT_VY_ID1 LIKE '%" + dto.getContactVyid1()
					+ "%' ");

		}
		if (dto.getContactVyid2() != null) {
			sb.append(" AND CONTACT_VY_ID2 LIKE '%" + dto.getContactVyid2()
					+ "%' ");

		}

		if (dto.getComment() != null) {
			sb.append(" AND COMMENT LIKE '%" + dto.getComment() + "%' ");

		}
		if (dto.getLastUpdatedBy() != null) {
			sb.append(" AND LAST_UPDATED_BY LIKE '%" + dto.getLastUpdatedBy()
					+ "%' ");

		}
		if (dto.getLastUpdatedOn() != null) {
			sb.append(" AND LAST_UPDATED_ON LIKE '%" + dto.getLastUpdatedOn()
					+ "%' ");

		}

		System.out.println(sb.toString());
		return (List<VySantSamajDO>) QueryManager.executeListQuery(dto, sb
				.toString());
	}

}
